/**
 * 
 */
package com.apinoo.basewebapp.spring.util;

import org.springframework.beans.factory.annotation.Value;

/**
 * @author Alejandro Pino Oreamuno
 *
 */
public class PaginationUtil {
	
//	private Logger logger = Logger.getLogger(getClass());
	
	// FIXME set maxResults with variable from properties
	@Value(value="${pagination.max_results}")
	private int maxResults = 10;
	

	/**
	 * Returs first register for Hibernate
	 * @param pag The page.
	 * @return The first result.
	 */
	public int getFirstResult(int pag) {
		return pag * maxResults - maxResults;
	}
	
	public int calculatePages(int regs) {
		if ( regs == 0) regs = 1;
		return (int) Math.ceil(regs * 1.0 / maxResults);
	}

	/**
	 * @return the maxResults
	 */
	public int getMaxResults() {
		return maxResults;
	}

	/**
	 * @param maxResults the maxResults to set
	 */
	public void setMaxResults(int maxResults) {
		this.maxResults = maxResults;
	}
	
	

}
